//
//  ViewController.m
//  30301
//
//  Created by student on 16/3/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic,weak) CALayer *layer;

@property (nonatomic,strong) UIView *moveView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.imageView.layer.cornerRadius = 50;
        self.imageView.layer.borderColor = [UIColor yellowColor].CGColor; //UIColre -> CGColor
    
        self.imageView.layer.borderWidth = 10;
            self.imageView.layer.masksToBounds = YES;
 
    self.imageView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.imageView.layer.shadowRadius = 15;
    
    self.imageView.layer.shadowOpacity  = 0.5f;
    CALayer *backLayer = [CALayer layer];
    backLayer.position = self.imageView.center;//中心点
    backLayer.anchorPoint = CGPointMake(0.5,0.5);// 挂载点
    backLayer.bounds = CGRectMake(0, 0, self.imageView.bounds.size.width-30, self.imageView.bounds.size.height-30);
    
    backLayer.backgroundColor = [UIColor greenColor].CGColor;
    backLayer.shadowColor = [UIColor yellowColor].CGColor;
    backLayer.shadowRadius = 20;
    backLayer.shadowOpacity = 0.8f;
    [self.view.layer insertSublayer:backLayer below:self.imageView.layer];
    
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(200, 250, 80, 80);
    layer.cornerRadius = 10;
    layer.masksToBounds = YES;
    //    layer.contents = (id)[UIImage imageNamed:@"2.png"].CGImage;// UIImage -> CGIamge
    // 背景色
    layer.backgroundColor = [UIColor redColor].CGColor;
    [self.view.layer addSublayer:layer];
    
    self.moveView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 80, 80)];
    [self.view addSubview:self.moveView];
    self.layer = self.moveView.layer;


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
    CGSize winSize = [UIScreen mainScreen].bounds.size;
    
    self.layer.position = CGPointMake(arc4random_uniform(winSize.width), arc4random_uniform(winSize.height));
    self.layer.cornerRadius = arc4random_uniform(1);
    self.layer.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1].CGColor;
    self.layer.borderColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:arc4random_uniform(255)/255.0].CGColor;
    self.layer.borderWidth = arc4random_uniform(1);
    self.layer.transform = CATransform3DMakeRotation(arc4random_uniform(M_PI*2), 1, 0, 0);
    
    [UIView commitAnimations];
}

@end
